
//
//  ZHomeViewController.m
//  ZQLearn
//
//  Created by 朵 on 2019/4/16.
//  Copyright © 2019年 admin. All rights reserved.
#import "ZFScanViewController.h"
#import "JKBannarView.h"
#import "BannerView.h"
#import "HDAlertView.h"
#import "SearchBar.h"
#import "ZHomeSearchResultVC.h"
#import "ZMoreVideoViewController.h"
#import "ZMoreViewController.h"
#import "ZARViewController.h"
#import "ZBookMsgDetailVC.h"
#import "StoreCollectionViewCell.h"
#import "NFourIconView.h"
#import "BannerModel.h"
#import "ZHomeViewController.h"
#import "ZStoreViewController.h"
#import "ZAnimationViewController.h"
#import "HomeHeaderCollectionViewCell.h"
#import "SDCycleScrollView.h"
#import "HomeModel.h"
#import "WideCollectionViewCell.h"
#import "FreshBookCell.h"
#import "OutVipCell.h"
#import "ZVideoViewController.h"
#import "ZSearchResultVC.h"
@interface ZHomeViewController()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,SDCycleScrollViewDelegate>

@property(nonatomic,strong)UICollectionView *collectionView;

//@property(nonatomic,strong)BannerView *bannerView;

@property (nonatomic,strong)ZVideoViewController *video;

@property (nonatomic,strong)ZAnimationViewController *animate;

///每个区的标题
@property(nonatomic,strong)NSArray *sectionTitleArray;
////这个数据将取代38行的那个数组的写法a
@property(nonatomic,strong)NSMutableArray *titleDataArray;

///这是那6个icon的视图 借鉴南宁云的做法
@property (nonatomic,strong)NFourIconView *iconView;

//@property (nonatomic,strong)VipView *vipView;
@property(nonatomic,strong)JKBannarView *bannerView;
@property(nonatomic,strong)SDCycleScrollView *cycleView;

@property(nonatomic,strong)NSMutableArray *bannerArray;

@property(nonatomic,strong)NSMutableArray *dataArray;
///热门推荐
@property(nonatomic,strong)NSMutableArray *hotRecommendArray;
///智秦动漫
@property(nonatomic,strong)NSMutableArray *comicArray;
///唐诗早教
@property(nonatomic,strong)NSMutableArray *poetArray;
///vip
@property (nonatomic,strong)NSMutableArray *vipArray;
///绘本
@property (nonatomic,strong)NSMutableArray *paintArray;
//体育动漫
@property (nonatomic,strong)NSMutableArray *sportArray;

//寓言故事
@property (nonatomic,strong)NSMutableArray *fableArray;

//生命故事
@property (nonatomic,strong)NSMutableArray *liftEduArray;

//新书上架
@property (nonatomic,strong)NSMutableArray *freshBookArray;
//经典图书
@property (nonatomic,strong)NSMutableArray *classicBookArray;
//猜你喜欢
@property (nonatomic,strong)NSMutableArray *guessLikeArray;

@property (nonatomic,strong)NSArray *idArray;
///导航条相关
@property(nonatomic,strong)UIImageView *barImageView;
@property (strong,nonatomic) SearchBar *searchBar;

@end


#define kLineNumber 3
#define kBarHeight 40
#define kSectionTitleHeight 35


NSString *const headReuseID = @"headReuse";
//#define cycleHight  160.f

///这个cellid 全局不能重复  所以建议写成宏的形式，而不是这种全局常量的形式
//NSString *const cellid = @"store";

#define cellIdentifier @"homehead"
#define SecondCellIdentifier @"store"
#define ThirddCellIdentifier @"wide" ///3，4区 cell 相同
#define FifthCellIdentifier @"out"  ///5区
#define FreshBookCellIdentifier @"freshbook"  ///5区

@implementation ZHomeViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    [self checkVip];

}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];

}


///搜索动作
- (void)searchAction:(UIButton *)btn{
    YYLog(@"jkajlj");
    ZHomeSearchResultVC *ss = [ZHomeSearchResultVC new];
    ///home这个单独做个页
//    ss.flag = @"home";
    [self.navigationController pushViewController:ss animated:YES];
}

-(void)viewDidLoad{
    
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = nil;
    
    [self.navigationItem setItemWithTitle:@"" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    [self initArray];
    //轮播图数据
    [self loadBanner];
   
    ///列表数据
    [self loadAllData];
    
    [self addIconView];
//    [self checkVip];
    [self checkIsSign];
    [self.view addSubview:self.collectionView];
     ///添加轮播图
    [self addBannerView];
    [self addSearchBar];
    ///
    [self addYuanhu];
//    self.collectionView.mj_header 
    
    ///签到接口检查是否已经签到过了
    ////添加顶部搜索栏
//    UIView *bar = [[UIView alloc]initWithFrame:CGRectMake(35, StatusBarHeight+5, ScreenWidth-70, 35)];
//    bar.backgroundColor = kBlackColor;
//    bar.layer.cornerRadius = 17.5f;
//    bar.layer.masksToBounds = YES;
//    bar.alpha = 0.3;
//    [self.view addSubview:bar];
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(searchAction:)];
//    [bar addGestureRecognizer:tap];
//
//    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(10, 8, 18, 18)];
//    img.image = WDImgName(@"sousuo");
//    [bar addSubview:img];
//
//    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(40, 10, 180, 16)];
//    titleLab.text = @"搜索绘本,视频,动漫";
//    titleLab.font = kFont15;
//    titleLab.textColor = kDarkGrayColor;
//    //    titleLab.backgroundColor = kMagentaColor;
//    [bar addSubview:titleLab];
//
}

///添加圆弧
-(void)addYuanhu{
    
    UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, cycleHight-29, ScreenWidth, 30)];
    imgV.image = WDImgName(@"yuanhu");
    [self.collectionView addSubview:imgV];
    
}

///添加搜索框
-(void)addSearchBar{
    ///签到接口检查是否已经签到过了
    ////添加顶部搜索栏
    UIView *bar = [[UIView alloc]initWithFrame:CGRectMake(35, StatusBarHeight+5, ScreenWidth-70, 35)];
    bar.backgroundColor = kBlackColor;
    bar.layer.cornerRadius = 17.5f;
    bar.layer.masksToBounds = YES;
    bar.alpha = 0.3;
    [self.view addSubview:bar];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(searchAction:)];
    [bar addGestureRecognizer:tap];
    
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(10, 8, 18, 18)];
    img.image = WDImgName(@"sousuo");
    [bar addSubview:img];
    
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(40, 10, 180, 16)];
    titleLab.text = @"搜索绘本,视频,动漫";
    titleLab.font = kFont15;
    titleLab.textColor = kDarkGrayColor;
    //    titleLab.backgroundColor = kMagentaColor;
    [bar addSubview:titleLab];
    
    UIImageView *scanImg = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-115, 3, 30, 28)];
    scanImg.userInteractionEnabled = YES;
    scanImg.image = WDImgName(@"nav_scan");
    [bar addSubview:scanImg];
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapScan)];
    [scanImg addGestureRecognizer:tap1];
}

#pragma mark - 扫码
///扫码
- (void)tapScan{
    
    ZFScanViewController * vc = [[ZFScanViewController alloc] init];
    vc.returnScanBarCodeValue = ^(NSString * barCodeString){
        [AFToast showText:barCodeString];
        //        self.resultLabel.text = [NSString stringWithFormat:@"扫描结果:\n%@",barCodeString];
        [AFToast showText:barCodeString];
//        NSLog(@"扫描结果的字符串======%@",barCodeString);
    };
    [self presentViewController:vc animated:YES completion:nil];
//    [self.navigationController pushViewController:vc animated:YES];
}

///数组初始化
-(void)initArray{
    self.sectionTitleArray = @[@"",@"热门推荐",@"智秦动漫英语",@"唐诗早教",@"",@"中国原创绘本",@"体育动漫",@"寓言故事",@"生命教育",@"新书上架",@"经典图书",@"猜你喜欢",];
   self.idArray =  @[@"",
                     @"2c913a7969e8b7740169e8eae0fa0027",@"2c913a79689845390168e4c5de0732fc",@"2c913a7968748f7d016882c332f913cc",@"2c913a7969e8b7740169e8d3b2ce0014",@"2c913a7969e89cea0169e8a6d6270006",@"2c913a7969e89cea0169e8a939a00007",@"2c913a7969e8b7740169e8ea9ddd0026",@"2c913a7969e8b7740169e8ea42270025",@"2c913a7969e89cea0169e8a6611e0005",@"2c913a7969e89cea0169e8a611de0004",@"2c913a7969b40af50169dd1df6d33094",];
    
    self.bannerArray = [NSMutableArray array];
    self.dataArray = [NSMutableArray array];
    self.hotRecommendArray = [NSMutableArray array];
    self.comicArray = [NSMutableArray array];
    self.poetArray = [NSMutableArray array];
    self.vipArray = [NSMutableArray array];
    self.paintArray = [NSMutableArray array];
    self.sportArray = [NSMutableArray array];
    self.fableArray = [NSMutableArray array];
    self.liftEduArray = [NSMutableArray array];
    self.freshBookArray = [NSMutableArray array];
    self.classicBookArray = [NSMutableArray array];
    self.guessLikeArray = [NSMutableArray array];
    self.titleDataArray = [NSMutableArray array];
    
}
#pragma mark - collectionView  创建
//流式布局
- (UICollectionViewFlowLayout *)flowLayout {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //整个 section 的四周边界的margin
    //    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    ///45行代码和  ScreenWidth-4（minimumLineSpacing*2）形成中间的小横线 如果横想间隙是0就没有中间那个小横线
    layout.minimumLineSpacing = 0.f;
    layout.minimumInteritemSpacing = 0.f;
    
//    layout.headerReferenceSize = CGSizeMake(ScreenWidth, SectionHeaderHeight);
    //    layout.itemSize = CGSizeMake((ScreenWidth-4)/3, 155);
    return layout;
    
}
- (UICollectionView *)collectionView {
    if (!_collectionView) {
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, -StatusBarHeight, ScreenWidth, ScreenHeight-TabBarHeight+StatusBarHeight) collectionViewLayout:[self flowLayout]];
        
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.showsVerticalScrollIndicator = YES;
        [self registerCell];
        WeakStament(ws);
        _collectionView.mj_header = [CustomRefreshHeader headerWithRefreshingBlock:^{
            [ws refreshData];
        }];
        _collectionView.backgroundColor = kBackgroundColor;
    }
    return _collectionView;
}
#pragma mark - 注册cell
- (void)registerCell {
    ///第1区的cell
    [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([HomeHeaderCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:cellIdentifier];
    ///第2区的cell
    [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([StoreCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:SecondCellIdentifier];
    ///第3区 第4区一样的cell
    //******* 第三区的cell 需要重新写一个  宽度要150  因为是以6为标准的，所以要算出大概的尺寸站屏幕的大小
    [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([WideCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:ThirddCellIdentifier];
    ///第5区 vip cell
    //    [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([OutVipCell class]) bundle:nil] forCellWithReuseIdentifier:FifthCellIdentifier];
    [_collectionView registerClass:[OutVipCell class] forCellWithReuseIdentifier:FifthCellIdentifier];
    ///新书上架的cell
    [_collectionView registerClass:[FreshBookCell class] forCellWithReuseIdentifier:FreshBookCellIdentifier];
    
    ///header
    [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headReuseID];
    
}

////懒加载
-(SDCycleScrollView *)cycleView{
    if (!_cycleView) {
        _cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, ScreenWidth, cycleHight) delegate:self placeholderImage:nil];
        _cycleView.currentPageDotColor = ThemeBlue;
        _cycleView.pageDotColor = kBackgroundColor;
        _cycleView.autoScrollTimeInterval = 4;
    }
    return _cycleView;
}
#pragma mark - 轮播图视图
-(void)addBannerView{
//    _cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, ScreenWidth, cycleHight) delegate:self placeholderImage:nil];
//    _cycleView.currentPageDotColor = ThemeBlue;
//    _cycleView.pageDotColor = kBackgroundColor;
//    _cycleView.autoScrollTimeInterval = 4;
//    _cycleView.imageURLStringsGroup = arr;
//    self.cycleView.imageURLStringsGroup = @[@"http://zhiqin-app.oss-cn-beijing.aliyuncs.com/15592966543251851.jpg",@"http://zhiqin-app.oss-cn-beijing.aliyuncs.com/15592966413365516.jpg",@"http://zhiqin-app.oss-cn-beijing.aliyuncs.com/15592968461898550.jpg"];
    [self.collectionView addSubview:self.cycleView];
    
    ///没问题的链接
//    self.cycleView.imageURLStringsGroup =@[@"http://pic18.nipic.com/20111130/8366510_125653691355_2.jpg",@"http://pic6.nipic.com/20091207/3337900_161732052452_2.jpg",@"http://pic1.16pic.com/00/11/71/16pic_1171350_b.jpg"];
    
    ///有问题的链接
//    self.cycleView.imageURLStringsGroup =@[@"http://zhiqin-app.oss-cn-beijing.aliyuncs.com/15592966543251851.jpg",@"http://zhiqin-app.oss-cn-beijing.aliyuncs.com/15592966413365516.jpg",];
    
    //http://zhiqin-app.oss-cn-beijing.aliyuncs.com/15592966543251851.jpg
    //http://zhiqin-app.oss-cn-beijing.aliyuncs.com/15592966413365516.jpg
    //http://zhiqin-app.oss-cn-beijing.aliyuncs.com/15592968461898550.jpg
    
    ///没问题的链接
//    self.cycleView.imageURLStringsGroup =@[@"http://pic.sijixiaoyuan.com/aa/20190415/9aa51b6299be4087890da43224087151.png",@"http://pic.sijixiaoyuan.com/aa/20190415/9aa51b6299be4087890da43224087151.png",@"http://pic.sijixiaoyuan.com/aa/20190415/9aa51b6299be4087890da43224087151.png"];
    //"http://pic.sijixiaoyuan.com/aa/20190415/9aa51b6299be4087890da43224087151.png"
//    _bannerView = [[BannerView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cycleHight)];
//    [self.collectionView addSubview:_bannerView];
//
//    NSMutableArray *imageViews = [[NSMutableArray alloc]init];
//    [imageViews addObjectsFromArray:@[@"http://pic18.nipic.com/20111130/8366510_125653691355_2.jpg",@"http://pic6.nipic.com/20091207/3337900_161732052452_2.jpg",@"http://pic1.16pic.com/00/11/71/16pic_1171350_b.jpg"]];
//    JKBannarView *bannerView = [[JKBannarView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), cycleHight) viewSize:CGSizeMake(CGRectGetWidth(self.view.bounds),cycleHight)];
////    bannerView.items = imageViews;
//    self.bannerView = bannerView;
//    [self.view addSubview:bannerView];
//
//    [bannerView imageViewClick:^(JKBannarView * _Nonnull barnerview, NSInteger index) {
//        NSLog(@"点击图片%ld",index);
//    }];
    
}
#pragma mark - 数据获取
///轮播图数据
- (void)loadBanner{
    WeakStament(ws);
    [self.bannerArray removeAllObjects];
    NSDictionary *dic = @{@"type":@"1"};
    [ZNetworkService getRequestWithBaseUrl:kBannerUrl setParameters:dic success:^(id result) {
        
        YYLog(@"%@",result);
        
        NSArray *array = result[@"result"];
        
        for (NSDictionary *dic in array) {
            
            BannerModel *model = [BannerModel mj_objectWithKeyValues:dic];
            model.imageUrl = [NSString stringWithFormat:@"%@%@",kPicServerUrl,model.photo];
            [ws.bannerArray addObject:model.imageUrl];
            
        }
        ///
//        ws.bannerView.items = [ws.bannerArray copy];
////        ws.bannerView.bannerArray = [ws.bannerArray copy];
        ///这里直接赋值会导致内存暴增 这里存在大问题
        YYLog(@"%@",self.bannerArray);
        
        ws.cycleView.imageURLStringsGroup  = ws.bannerArray;
        
        [ws endRefresh];
        
    } fail:^(NSError *error) {
        [self endRefresh];
    } delegater:nil];
}

- (void)refreshData{
    [self loadAllData];
    [self endRefresh];
}
- (void)endRefresh{
    [self.collectionView.mj_header endRefreshing];
    [self.collectionView.mj_footer endRefreshing];
}

///首页所有信息接口

- (void)loadAllData{
    [ZNetworkService getRequestWithBaseUrl:kHomeAllInfoUrl setParameters:@{} success:^(id result) {
        YYLog(@"%@",result[@"result"]);
        [self.dataArray removeAllObjects];
        NSArray *array = result[@"result"];
        if (array.count>0) {
            for (NSDictionary *dic in array) {
//                HomeModel *model = [HomeModel new];
//                [model setValuesForKeysWithDictionary:dic];
                ///尽量用这个替代上面的方式，如果返回的是id等系统关键字时
                 HomeModel *model = [HomeModel mj_objectWithKeyValues:dic];
                YYLog(@"%@",model.ID);
                NSMutableArray *tempArray = [NSMutableArray array];
                for (NSDictionary *subDic in model.qualityEducationInfoDTOList) {
//                    HomeSubModel *subModel = [HomeSubModel new];
//                    [subModel setValuesForKeysWithDictionary:subDic];
                    HomeSubModel *subModel = [HomeSubModel mj_objectWithKeyValues:subDic];
                    [tempArray addObject:subModel];
                }
                model.qualityEducationInfoDTOList = [tempArray copy];
                [self.dataArray addObject:model];
                ////把id单独存起来，为了跳转到更多使用
                NSString *mid = model.ID;
                [self.titleDataArray addObject:mid];
                
               
            }
            [self.titleDataArray removeObjectAtIndex:2];
            [self.titleDataArray removeObjectAtIndex:3];
            [self.titleDataArray removeObjectAtIndex:5];
            [self.titleDataArray removeObjectAtIndex:8];
            [self.titleDataArray removeObjectAtIndex:10];
            
            [self.titleDataArray insertObject:@"" atIndex:0];
            
             YYLog(@"id数组：%@",self.titleDataArray);
            YYLog(@"id数组：%@",self.titleDataArray);
            ////这里需要将这个数组的数据拿出来进行过滤，为了那个标题和更多的ID 需要去掉广告栏相关的model
//            [self.titleDataArray addObjectsFromArray:self.dataArray];//这局代码不能用self.dataArray copy
//            [self.titleDataArray removeObjectAtIndex:2];
//            [self.titleDataArray removeObjectAtIndex:3];
//            [self.titleDataArray removeObjectAtIndex:5];
//            [self.titleDataArray removeObjectAtIndex:8];
//            [self.titleDataArray removeObjectAtIndex:10];
            ////数组遍历删除 这个方法会直接崩溃掉
//            for (HomeModel *model in self.titleDataArray) {
//                if ([model.name containsString:@"广告"]) {
//                    [self.titleDataArray removeObject:model];
//                }
//            }
//            [self.titleDataArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//                HomeModel *model = self.titleDataArray[idx];
//                if ([model.name containsString:@"广告"]) {
//                    [self.titleDataArray removeObject:model];
//                }
//            }];
////            YYLog(@"%@",self.titleDataArray[0]);
//            YYLog(@"数组大小：%ld",self.titleDataArray.count);
////            HomeModel *mjjjodel = self.titleDataArray[0];
////            YYLog(@"数组大小：%@",mjjjodel.name);
//            YYLog(@"%ld",self.titleDataArray.count);
            ///拼装热门推荐需要用到的数据***************
            HomeModel *model = self.dataArray[0];
            [self.hotRecommendArray removeAllObjects];
            for (HomeSubModel *subModel in model.qualityEducationInfoDTOList) {
                MidModel *mmodel = [MidModel new];
                mmodel.name = subModel.bookInfo[@"name"];
                mmodel.ID = subModel.bookInfo[@"id"];
                mmodel.content = subModel.bookInfo[@"content"];
                mmodel.isPaint = subModel.bookInfo[@"isPaint"];
                mmodel.author = subModel.bookInfo[@"author"];
                mmodel.firstPhoto = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.bookInfo[@"firstPhoto"]];
                YYLog(@"%@%@",mmodel.name,mmodel.firstPhoto);
                [self.hotRecommendArray addObject:mmodel];
            }
            ///拼装智秦动漫数据***************
            HomeModel *model1 = self.dataArray[1];
            [self.comicArray removeAllObjects];
            for (HomeSubModel *subModel in model1.qualityEducationInfoDTOList) {
                MidModel *mmodel = [MidModel new];
                mmodel.name = subModel.videoInfo[@"name"];
                mmodel.firstPhoto = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.videoInfo[@"photo"]];
                mmodel.price = subModel.videoInfo[@"price"];
                NSString *vUrl = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.videoInfo[@"videoUrl"]];;
                mmodel.videoUrl = vUrl;
                mmodel.ID = subModel.videoInfo[@"id"];
                YYLog(@"%@%@",vUrl,mmodel.firstPhoto);
                [self.comicArray addObject:mmodel];
            }
            ///拼装唐诗早教数据***************
            HomeModel *model2 = self.dataArray[3];
            [self.poetArray removeAllObjects];
            for (HomeSubModel *subModel in model2.qualityEducationInfoDTOList) {
                MidModel *mmodel = [MidModel new];
                mmodel.name = subModel.name;
                mmodel.firstPhoto = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.videoInfo[@"photo"]];
                mmodel.price = subModel.videoInfo[@"price"];
                mmodel.ID = subModel.videoInfo[@"id"];
                NSString *vUrl = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.videoInfo[@"videoUrl"]];;
                mmodel.videoUrl = vUrl;
                YYLog(@"%@%@",vUrl,mmodel.firstPhoto);
                [self.poetArray addObject:mmodel];
            }
            
            ///拼装vip数据***************
            HomeModel *model3 = self.dataArray[5];
            [self.vipArray removeAllObjects];
            for (HomeSubModel *subModel in model3.qualityEducationInfoDTOList) {
                
                MidModel *mmodel = [MidModel new];
                ///此处可能会有冲突
                mmodel.ID = [NSString stringWithFormat:@"%@",subModel.bookInfo[@"id"]];
                mmodel.name = [NSString stringWithFormat:@"%@",subModel.bookInfo[@"name"]];
                mmodel.firstPhoto = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.bookInfo[@"photo"]];
                mmodel.ID = subModel.bookInfo[@"id"];
                mmodel.author = subModel.bookInfo[@"author"];
                mmodel.isPaint = subModel.bookInfo[@"isPaint"];
               mmodel.content = [NSString stringWithFormat:@"%@",subModel.bookInfo[@"content"]]; YYLog(@"**%@*%@",mmodel.name,mmodel.firstPhoto);
                [self.vipArray addObject:mmodel];
            }
            
            ///拼装原创绘本数据***************
            HomeModel *model4 = self.dataArray[6];
            [self.paintArray removeAllObjects];
            for (HomeSubModel *subModel in model4.qualityEducationInfoDTOList) {
                MidModel *mmodel = [MidModel new];
                mmodel.name = [NSString stringWithFormat:@"%@",subModel.bookInfo[@"name"]];;
                mmodel.firstPhoto = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.bookInfo[@"photo"]];
                mmodel.ID = subModel.bookInfo[@"id"];
                mmodel.content = subModel.bookInfo[@"content"];
                mmodel.author = subModel.bookInfo[@"author"];
                mmodel.isPaint = subModel.bookInfo[@"isPaint"];
                YYLog(@"%@%@",mmodel.name,mmodel.firstPhoto);
                [self.paintArray addObject:mmodel];
            }
            ///拼装体育动漫数据***************
            HomeModel *model5 = self.dataArray[8];
            [self.sportArray removeAllObjects];
            for (HomeSubModel *subModel in model5.qualityEducationInfoDTOList) {
                MidModel *mmodel = [MidModel new];
                mmodel.name = [NSString stringWithFormat:@"%@",subModel.videoInfo[@"name"]];;
                mmodel.firstPhoto = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.videoInfo[@"photo"]];
                mmodel.price = subModel.videoInfo[@"price"];
                mmodel.ID = subModel.videoInfo[@"id"];
                NSString *vUrl = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.videoInfo[@"videoUrl"]];;
                mmodel.videoUrl = vUrl;
                YYLog(@"%@%@",mmodel.name,mmodel.firstPhoto);
                [self.sportArray addObject:mmodel];
            }

            ///拼装寓言故事数据***************
            HomeModel *model6 = self.dataArray[9];
            [self.fableArray removeAllObjects];
            for (HomeSubModel *subModel in model6.qualityEducationInfoDTOList) {
                MidModel *mmodel = [MidModel new];
                mmodel.name = [NSString stringWithFormat:@"%@",subModel.videoInfo[@"name"]];;
                mmodel.firstPhoto = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.videoInfo[@"photo"]];
                mmodel.price = subModel.videoInfo[@"price"];
                mmodel.ID = subModel.videoInfo[@"id"];
                NSString *vUrl = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.videoInfo[@"videoUrl"]];;
                mmodel.videoUrl = vUrl;
                YYLog(@"%@%@",mmodel.name,mmodel.firstPhoto);
                [self.fableArray addObject:mmodel];
            }
            
            ///拼装life教育数据***************
            HomeModel *model7 = self.dataArray[10];
            [self.liftEduArray removeAllObjects];
            for (HomeSubModel *subModel in model7.qualityEducationInfoDTOList) {
                MidModel *mmodel = [MidModel new];
                mmodel.name = [NSString stringWithFormat:@"%@",subModel.videoInfo[@"name"]];;
                mmodel.firstPhoto = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.videoInfo[@"photo"]];
                mmodel.price = subModel.videoInfo[@"price"];
                mmodel.ID = subModel.videoInfo[@"id"];
                NSString *vUrl = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.videoInfo[@"videoUrl"]];;
                mmodel.videoUrl = vUrl;
                YYLog(@"%@%@",mmodel.name,mmodel.firstPhoto);
                [self.liftEduArray addObject:mmodel];
            }
            ///拼装新书上架数据***************
            HomeModel *model8 = self.dataArray[12];
            [self.freshBookArray removeAllObjects];
            for (HomeSubModel *subModel in model8.qualityEducationInfoDTOList) {
                
                MidModel *mmodel = [MidModel new];
                ///此处可能会有冲突
                mmodel.ID = [NSString stringWithFormat:@"%@",subModel.bookInfo[@"id"]];
                mmodel.name = [NSString stringWithFormat:@"%@",subModel.bookInfo[@"name"]];
                mmodel.firstPhoto = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.bookInfo[@"photo"]];
                
                mmodel.isPaint = subModel.bookInfo[@"isPaint"];
                
                mmodel.author = subModel.bookInfo[@"author"];
                mmodel.content = [NSString stringWithFormat:@"%@",subModel.bookInfo[@"content"]]; YYLog(@"**%@*%@",mmodel.name,mmodel.firstPhoto);
                [self.freshBookArray addObject:mmodel];
            }
            ///拼装经典图书数据***************
            HomeModel *model9 = self.dataArray[13];
            [self.classicBookArray removeAllObjects];
            for (HomeSubModel *subModel in model9.qualityEducationInfoDTOList) {
                MidModel *mmodel = [MidModel new];
                mmodel.name = [NSString stringWithFormat:@"%@",subModel.bookInfo[@"name"]];;
                mmodel.firstPhoto = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.bookInfo[@"photo"]];
                mmodel.ID = subModel.bookInfo[@"id"];
                mmodel.content = subModel.bookInfo[@"content"];
                mmodel.author = subModel.bookInfo[@"author"];
                mmodel.isPaint = subModel.bookInfo[@"isPaint"];
                mmodel.catelogType = subModel.bookInfo[@"catelogType"];
                YYLog(@"%@%@",mmodel.name,mmodel.firstPhoto);
                [self.classicBookArray addObject:mmodel];
            }
            
            ///拼装猜你喜欢图书数据***************
            HomeModel *model10 = self.dataArray[15];
            [self.guessLikeArray removeAllObjects];
            for (HomeSubModel *subModel in model10.qualityEducationInfoDTOList) {
                MidModel *mmodel = [MidModel new];
                mmodel.name = [NSString stringWithFormat:@"%@",subModel.bookInfo[@"name"]];;
                mmodel.firstPhoto = [NSString stringWithFormat:@"%@%@",kPicServerUrl,subModel.bookInfo[@"photo"]];
                mmodel.ID = subModel.bookInfo[@"id"];
                mmodel.content = subModel.bookInfo[@"content"];
                mmodel.isPaint = subModel.bookInfo[@"isPaint"];
                mmodel.author = subModel.bookInfo[@"author"];
                YYLog(@"%@%@",mmodel.name,mmodel.firstPhoto);
                [self.guessLikeArray addObject:mmodel];
            }
            ///在双重for循环的外层刷新collectionView
            [self.collectionView reloadData];
        }
    } fail:^(NSError *error) {
        
    } delegater:nil];
}

#pragma mark - 添加6个icon图标
- (void)addIconView {
    WeakStament(wself);
    self.iconView = [[NFourIconView alloc]initWithFrame:CGRectMake(0,cycleHight, ScreenWidth, fourIconHight)];
    self.iconView.iconArray = @[@"dmg",@"hb",@"jc",@"jf",@"ar",@"sc"];
    self.iconView.titleArray = @[@"动漫馆",@"绘本馆",@"教材馆",@"教辅馆",@"AR馆",@"商城"];
    
    self.iconView.indexBlock = ^(NSInteger indexNum, NFourIconModel *model) {
        YYLog(@"%ld",indexNum);
        [wself jumpToIconViewList:indexNum];
    };
    [self.collectionView addSubview:self.iconView];
}
///iconview 点击跳转事件
- (void)jumpToIconViewList:(NSInteger)num{
    if (num ==0) {
//        self.animate.name = @"动漫馆";
        ZAnimationViewController *an = [ZAnimationViewController new];
        an.name = @"动漫馆";
        [self.navigationController pushViewController:an animated:YES];
    }else if (num==1){
        ZAnimationViewController *an = [ZAnimationViewController new];
        an.name = @"绘本馆";
        [self.navigationController pushViewController:an animated:YES];
    }else if (num==2){
        ZAnimationViewController *an = [ZAnimationViewController new];
        an.name = @"教材馆";
        [self.navigationController pushViewController:an animated:YES];
    }else if (num==3){
        ZAnimationViewController *an = [ZAnimationViewController new];
        an.name = @"教辅馆";
        [self.navigationController pushViewController:an animated:YES];
    }else if (num==4){
        ZARViewController *ar = [ZARViewController new];
        [self.navigationController pushViewController:ar animated:YES];
    }else{
        ZStoreViewController *store = [ZStoreViewController new];
        [self.navigationController pushViewController:store animated:YES];
    }
}

#pragma datasource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 12;
}

#pragma mark - 调整个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    switch (section) {
        case 0:case 4:case 9:
        
        {
            return 1;
        }
            break;
        case 1:
        {
            return self.hotRecommendArray.count;
        }
            break;
            
        case 2:
            
        {
            
            return self.comicArray.count+1;
            //            return 5;
            ///因为下面的广告条没有数据，所以需要加1
            
        }
            
            break;
        case 3:
            
        {
            
            return self.poetArray.count+1;
            ///因为下面的广告条没有数据，所以需要加1
            
        }
            
            break;
        case 5:
        {
            
            //最后的加1是广告条
            return self.paintArray.count+1;
            
        }
            break;
        case 6:
        {
            
            //最后的加1是广告条
            return self.sportArray.count;
            
        }
            break;
        case 7:
        {
            
            //最后的加1是广告条
            return self.fableArray.count;
            
        }
            break;
        case 8:
        {
            
            //最后的加1是广告条
            return self.liftEduArray.count+1;
            
        }
            break;
        case 10:
        {
            
            return self.classicBookArray.count+1;
            
        }
            break;
        case 11:
        {
            
            return self.guessLikeArray.count;
            
        }
            break;

            
        default:
            return 0;
            break;
    }
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    ZBookMsgDetailVC *msg = [ZBookMsgDetailVC new];
    
    WeakStament(ws);
    
    switch (indexPath.section) {
        case 0:
        {
            ///轮播图和那六个图标
            HomeHeaderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            return cell;
        }
            break;
        case 1:
        {
            MidModel *model;
            if (self.hotRecommendArray.count>indexPath.row) {
                
                ///防止数组越界的判断
                model = self.hotRecommendArray[indexPath.row];
                
            }
            StoreCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:SecondCellIdentifier forIndexPath:indexPath];
            cell.heightConstant.constant = IS_IPhoneX_All?125.f:110.f;
            cell.nameLab.text = model.name;
            [cell.headImg sd_setImageWithURL:[NSURL URLWithString:model.firstPhoto] placeholderImage:nil];
            cell.backgroundColor = kWhiteColor;
            return cell;
        }
            break;
            
        case 2:
        {
            
            MidModel *model;
            if (self.comicArray.count>indexPath.row) {
                model = self.comicArray[indexPath.row];
            }
            WideCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ThirddCellIdentifier forIndexPath:indexPath];
            if (indexPath.row>3) {
                cell.headImg.image = WDImgName(@"画板蓝色");
                cell.nameLab.text = @"";
            }else{
                
                cell.nameLab.text = model.name;
                [cell.headImg sd_setImageWithURL:[NSURL URLWithString:model.firstPhoto] placeholderImage:nil];
            }
            return cell;
        }
            break;
        case 3:
        {
            
            MidModel *model;
            if (self.poetArray.count>indexPath.row) {
                model = self.poetArray[indexPath.row];
            }
            WideCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ThirddCellIdentifier forIndexPath:indexPath];
            if (indexPath.row==4) {
                cell.headImg.image = WDImgName(@"读书季");
                cell.nameLab.text = @"";
                
            }else{
                cell.nameLab.text = model.name;
                [cell.headImg sd_setImageWithURL:[NSURL URLWithString:model.firstPhoto] placeholderImage:nil];
            }
            return cell;
        }
            break;
            
        case 4:
        {
            
//            FreshBookCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:FreshBookCellIdentifier forIndexPath:indexPath];
//            cell.dataArray = [self.vipArray copy];
//            cell.indexBlock = ^(MidModel * _Nonnull model) {
//                msg.MModel = model;
//                [ws.navigationController pushViewController:msg animated:YES];
//            };
            
            ///vip
            WeakStament(ws);
            OutVipCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:FifthCellIdentifier forIndexPath:indexPath];
            cell.dataArray = [self.vipArray copy];
            ///这个是cell中嵌套collectionView 所以这里处理，其他的是在did 点击事件中处理
            cell.vipCellBlock = ^(NSInteger index, MidModel * _Nonnull model) {
                YYLog(@"%ld,%@",index,model);
            msg.MModel = model;
            [ws.navigationController pushViewController:msg animated:YES];
            };
            return cell;
        }
            break;
        case 5:
        {
            ///原创绘本
            MidModel *model;
            if (self.paintArray.count>indexPath.row) {
                
                ///防止数组越界的判断
                model = self.paintArray[indexPath.row];
                
            }
            
            StoreCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:SecondCellIdentifier forIndexPath:indexPath];
            cell.heightConstant.constant = IS_IPhoneX_All?165.f:150.f;
            cell.nameLab.text = model.name;
            if (indexPath.row==6) {
                
                cell.headImg.image = WDImgName(@"中考");
                
            }else{
               [cell.headImg sd_setImageWithURL:[NSURL URLWithString:model.firstPhoto] placeholderImage:nil];
            }
            cell.backgroundColor = kWhiteColor;
            return cell;
        }
            break;
        case 6:
        {
            
            MidModel *model;
            if (self.sportArray.count>indexPath.row) {
                model = self.sportArray[indexPath.row];
            }
            WideCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ThirddCellIdentifier forIndexPath:indexPath];
                cell.nameLab.text = model.name;
                [cell.headImg sd_setImageWithURL:[NSURL URLWithString:model.firstPhoto] placeholderImage:nil];
            
            return cell;
        }
            break;
        case 7:
        {
            
            MidModel *model;
            if (self.fableArray.count>indexPath.row) {
                model = self.fableArray[indexPath.row];
            }
            WideCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ThirddCellIdentifier forIndexPath:indexPath];
            cell.nameLab.text = model.name;
            [cell.headImg sd_setImageWithURL:[NSURL URLWithString:model.firstPhoto] placeholderImage:nil];
            
            return cell;
        }
            break;
        case 8:
        {
            
            MidModel *model;
            if (self.liftEduArray.count>indexPath.row) {
                model = self.liftEduArray[indexPath.row];
            }
            WideCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ThirddCellIdentifier forIndexPath:indexPath];
            cell.nameLab.text = model.name;
            if (indexPath.row==4) {
                
                cell.headImg.image = WDImgName(@"画板 1");
                
            }else{
                [cell.headImg sd_setImageWithURL:[NSURL URLWithString:model.firstPhoto] placeholderImage:nil];
            }
            
            
            return cell;
        }
            break;
        case 9:
        {
            ///新书上架
            FreshBookCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:FreshBookCellIdentifier forIndexPath:indexPath];
            cell.dataArray = [self.freshBookArray copy];
            cell.indexBlock = ^(MidModel * _Nonnull model) {
            msg.MModel = model;
                [ws.navigationController pushViewController:msg animated:YES];
            };
            return cell;
        }
            break;
            
        case 10:
        {
            ///经典图书
            MidModel *model;
            if (self.classicBookArray.count>indexPath.row) {
                
                ///防止数组越界的判断
                model = self.classicBookArray[indexPath.row];
                
            }
            StoreCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:SecondCellIdentifier forIndexPath:indexPath];
            cell.heightConstant.constant = IS_IPhoneX_All?165.f: 150.f;
            cell.nameLab.text = model.name;
            if (indexPath.row==6) {
                
                cell.headImg.image = WDImgName(@"成长必读");
                
            }else{
                [cell.headImg sd_setImageWithURL:[NSURL URLWithString:model.firstPhoto] placeholderImage:nil];
            }
            cell.backgroundColor = kWhiteColor;
            return cell;
        }
            break;
            
        case 11:
        {
            //猜你喜欢
            MidModel *model;
            if (self.guessLikeArray.count>indexPath.row) {
                
                ///防止数组越界的判断
                model = self.guessLikeArray[indexPath.row];
                
            }
            StoreCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:SecondCellIdentifier forIndexPath:indexPath];
            cell.heightConstant.constant = IS_IPhoneX_All?165.f:150.f;
            cell.nameLab.text = model.name;
           
            [cell.headImg sd_setImageWithURL:[NSURL URLWithString:model.firstPhoto] placeholderImage:nil];
            
            cell.backgroundColor = kWhiteColor;
            return cell;
        }
            break;
            
        default:
            break;
    }
    return nil;
    
}
#pragma mark - 懒加载控制器 视频详情

-(ZVideoViewController *)video{
    if (!_video) {
        _video = [[ZVideoViewController alloc]init];
    }
    return _video;
}

#pragma mark - delegate  section header

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    YYLog(@"当前索引:%ld",(long)indexPath.section);
//    YYLog(@"%@",self.titleDataArray);
//    if (self.titleDataArray.count>indexPath.section) {
//        NSString *cid = self.titleDataArray[indexPath.section];
//        YYLog(@"heheh****%@",cid);
//    }
    UICollectionReusableView *reusabelView = nil;
    //    XALifeListModel *model = self.dataArray[indexPath.section-BannerIndex];
    if (kind == UICollectionElementKindSectionHeader) {
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SectionHeaderHeight)];
        bgView.backgroundColor = kWhiteColor;
        UIView *sepratorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 11)];
        sepratorView.backgroundColor = NColorFrom16RGB(0xeeeeee);
        ///标题前面的黄色图标
        UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 2, 15)];
        tipLabel.backgroundColor = [UIColor orangeColor];
        
        ////标题
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, ScreenWidth, SectionHeaderHeight-5)];
        //        titleLabel.text = model.title;
        titleLabel.text = self.sectionTitleArray[indexPath.section];
        ///更多按钮
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(ScreenWidth-65, 15, 60, 40);
        btn.titleLabel.font = kFont14;
        [btn setTitleColor:kBackBlue forState:UIControlStateNormal];
        [btn setTitle:@"更多>" forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(moreActon:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = indexPath.section;
//        titleLabel.text = model.name;
        UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headReuseID forIndexPath:indexPath];
        ///循环遍历移除之前视图
        [headerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        
        [headerView addSubview:bgView];
        [headerView addSubview:tipLabel];
        [headerView addSubview:sepratorView];
        [headerView addSubview:titleLabel];
        [headerView addSubview:btn];
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, SectionHeaderHeight-5, ScreenWidth, 0.5)];
        line.backgroundColor = kLightGrayColor;
//        [headerView addSubview:line];
        reusabelView = headerView;
    }
    return reusabelView;
}

///section header 尺寸  这个如果尺寸不变的话可以可以直接设置成  . 点属性
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    if (section==0||section==4) {
        return CGSizeZero;
    }
    return CGSizeMake(ScreenWidth, SectionHeaderHeight);
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    ZBookMsgDetailVC *msg = [ZBookMsgDetailVC new];
    MidModel *model;
    
    switch (indexPath.section) {
        case 1:
        {
            if (self.hotRecommendArray.count>indexPath.row) {
            
            model = self.hotRecommendArray[indexPath.row];
            model.picUrl = model.firstPhoto;
            YYLog(@"%@",model.picUrl);
            msg.MModel = model;
            [self.navigationController pushViewController:msg animated:YES];
            }
        }
            break;
        case 2:
        {
            ///动漫
            if (self.comicArray.count>indexPath.row) {
                
                model = self.comicArray[indexPath.row];
                model.picUrl = model.firstPhoto;
                YYLog(@"%@",model.picUrl);
                self.video.MModel = model;
                [self.navigationController pushViewController:self.video animated:YES];
            }
            
        }
            break;
        case 3:
        {
            ///唐诗早教
             if (self.poetArray.count>indexPath.row) {
            model = self.poetArray[indexPath.row];
            model.picUrl = model.firstPhoto;
            YYLog(@"%@",model.picUrl);
            self.video.MModel = model;
            [self.navigationController pushViewController:self.video animated:YES];
             }
        }
            break;
            
            
        case 4:
        {
            ///vip
            if (self.vipArray.count>indexPath.row) {
                
            
            model = self.vipArray[indexPath.row];
            model.picUrl = model.firstPhoto;
            YYLog(@"%@",model.picUrl);
            msg.MModel = model;
            [self.navigationController pushViewController:msg animated:YES];
            
            }
        }
            break;
        case 5:
        {
            ///原创绘本
            if (self.paintArray.count>indexPath.row) {
                
            
            model = self.paintArray[indexPath.row];
            model.picUrl = model.firstPhoto;
            YYLog(@"%@",model.picUrl);
            msg.MModel = model;
            [self.navigationController pushViewController:msg animated:YES];
            }
        }
            break;
            
        case 6:
        {
            ///体育动漫
            if (self.sportArray.count>indexPath.row) {
                
            
            model = self.sportArray[indexPath.row];
            model.picUrl = model.firstPhoto;
            YYLog(@"%@",model.picUrl);
            self.video.MModel = model;
            [self.navigationController pushViewController:self.video animated:YES];
            }
        }
            break;
        case 7:
        {
            ///寓言故事
            if (self.fableArray.count>indexPath.row) {
            model = self.fableArray[indexPath.row];
            model.picUrl = model.firstPhoto;
            YYLog(@"%@",model.picUrl);
            self.video.MModel = model;
            [self.navigationController pushViewController:self.video animated:YES];
            }
        }
            break;
        case 8:
        {
            ///生命教育
            if (self.liftEduArray.count>indexPath.row) {
            model = self.liftEduArray[indexPath.row];
            model.picUrl = model.firstPhoto;
            YYLog(@"%@",model.picUrl);
            self.video.MModel = model;
            [self.navigationController pushViewController:self.video animated:YES];
            }
        }
            break;
        case 10:
        {
            
            ///经典图书
            if (self.classicBookArray.count>indexPath.row) {
            model = self.classicBookArray[indexPath.row];
            model.picUrl = model.firstPhoto;
            YYLog(@"%@",model.picUrl);
            msg.MModel = model;
            [self.navigationController pushViewController:msg animated:YES];
            }
        }
            break;
            
        case 11:
        {
            
            ///猜你喜欢
            if (self.guessLikeArray.count>indexPath.row) {
            model = self.guessLikeArray[indexPath.row];
            model.picUrl = model.firstPhoto;
            YYLog(@"%@",model.picUrl);
            msg.MModel = model;
            [self.navigationController pushViewController:msg animated:YES];
            }
        }
            break;
            
        default:
            
            break;
    }
}

#pragma mark - delegateFlowlayout
//cell尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    switch (indexPath.section) {
        case 0:
        {
             return CGSizeMake(ScreenWidth, 286.f);
        }
            break;
            
        case 1:
        {
            return CGSizeMake(ScreenWidth/4,IS_IPhoneX_All?165.f:150.f);
        }
            break;
        case 4:
        {
            return CGSizeMake(ScreenWidth, 230.f);
        }
            break;
        
            ///case 合并写法
            
        case 2:
        case 3:case 6:case 7:case 8:
        {
            ///最后这一个是广告条
            if (indexPath.row>3) {
                
                return CGSizeMake(ScreenWidth-10, 150.f);
            }
            return CGSizeMake(ScreenWidth/2-5, 150.f);
        }
            break;
        case 5:case 10:
        {
            ///最后这一个是广告条
            if (indexPath.row>5) {
                
                return CGSizeMake(ScreenWidth, 125.f);
            }
            return CGSizeMake(ScreenWidth/3,IS_IPhoneX_All?206.f:185.f);
        }
            break;

        case 9:
        {
            return CGSizeMake(ScreenWidth, 128.f);
        }
            break;
        case 11:
        {
            return CGSizeMake(ScreenWidth/3, IS_IPhoneX_All?205.f: 185.f);
        }
            break;
        default:
            break;
    }
    
    return CGSizeZero;
}
///insets
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
    switch (section) {
        case 0:
            
        {
            return UIEdgeInsetsZero;
        }
            break;
            
        case 2:
        case 3:case 8:
        {
            ///这里也控制着中间是否有缝隙 是控制纵向缝隙的
            
            return UIEdgeInsetsMake(0, 5, 0, 5);
        }
            break;
        case 6:case 7:
        {
            ///这里也控制着中间是否有缝隙 是控制纵向缝隙的
            return UIEdgeInsetsMake(0, 5, 0, 5);
        }
            
        default:
            return UIEdgeInsetsMake(0, 0, 0, 0);
            break;
    }
    
}

#pragma mark - 点击更多
-(void)moreActon:(UIButton *)btn
{
    YYLog(@"%ld",btn.tag);
    YYLog(@"%@",self.idArray[btn.tag]);
    ZMoreViewController *more ;
    ZMoreVideoViewController *mVideo;
    switch (btn.tag) {
        case 1:
        {
            more = [ZMoreViewController new];
            more.ttitle  = @"热门推荐";
            more.cateId = self.idArray[btn.tag];
            [UserModel shareInstance].isLib = YES;
            [self.navigationController pushViewController:more animated:YES];
        }
            break;
            
        case 2:
        {
            mVideo = [ZMoreVideoViewController new];
            mVideo.ttitle  = @"智秦动漫英语";
            mVideo.cateId = self.idArray[btn.tag];
            [self.navigationController pushViewController:mVideo animated:YES];
        }
            break;
            
        case 3:
        {
            mVideo = [ZMoreVideoViewController new];
            mVideo.ttitle  = @"唐诗早教";
            mVideo.cateId = self.idArray[btn.tag];
            [self.navigationController pushViewController:mVideo animated:YES];
        }
            break;
            
        case 4:
        {
            
        }
            break;
            
        case 5:
        {
            more = [ZMoreViewController new];
            more.ttitle  = @"原创绘本";
            more.cateId = self.idArray[btn.tag];
            [UserModel shareInstance].isLib = YES;
            [self.navigationController pushViewController:more animated:YES];
        }
            break;
            
        case 6:
        {
            mVideo = [ZMoreVideoViewController new];
            mVideo.ttitle  = @"体育动漫";
            mVideo.cateId = self.idArray[btn.tag];
            [self.navigationController pushViewController:mVideo animated:YES];
        }
            break;
            
        case 7:
        {
            mVideo = [ZMoreVideoViewController new];
            mVideo.ttitle  = @"寓言故事";
            mVideo.cateId = self.idArray[btn.tag];
            [self.navigationController pushViewController:mVideo animated:YES];
        }
            break;
            
        case 8:
        {
            mVideo = [ZMoreVideoViewController new];
            mVideo.ttitle  = @"生命教育";
            mVideo.cateId = self.idArray[btn.tag];
            [self.navigationController pushViewController:mVideo animated:YES];
        }
            break;
            
        case 9:
        {
            more = [ZMoreViewController new];
            more.ttitle  = @"新书上架";
            more.cateId = self.idArray[btn.tag];
            [UserModel shareInstance].isLib = YES;
            [self.navigationController pushViewController:more animated:YES];
        }
            break;
        case 10:
        {
            more = [ZMoreViewController new];
            more.ttitle  = @"经典图书";
            more.cateId = self.idArray[btn.tag];
            [UserModel shareInstance].isLib = YES;
            [self.navigationController pushViewController:more animated:YES];
        }
            break;
        case 11:
        {
            more = [ZMoreViewController new];
            more.ttitle  = @"猜你喜欢";
            more.cateId = self.idArray[btn.tag];
            [UserModel shareInstance].isLib = YES;
            [self.navigationController pushViewController:more animated:YES];
        }
            break;
            
        default:
            break;
    }
    
    
}
#pragma mrak - SDCycleScrollViewDelegate
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    
    YYLog(@"%ld",index);
    //    if (_bannerBlock) {
    //        _bannerBlock(index);
    //    }
}


#pragma mark - 判断是否是vip
-(void)checkVip{
    
    NSDictionary *dic = @{@"id":[UserInfoSave shareInstance].uid?:@""};
    [ZNetworkService postRequestWithBaseUrl:kCheckVipUrl setParameters:dic success:^(id result) {
        YYLog(@"%@",result);
        if ([result[@"errorCode"]integerValue]==0) {
            
            NSDictionary *dict = result[@"result"];
            NSNumber *number = dict[@"isVip"];
//            YYLog(@"当前的vip:%@",number);
            ///1 是    0 不是
            [UserModel shareInstance].isVip = number;
        }
    } fail:^(NSError *error) {
    } delegater:nil];
}
#pragma mark - 判断当天是否签到
-(void)checkIsSign{
    NSDictionary *dic = @{@"userInfo.id":[UserInfoSave shareInstance].uid?:@""};
    [ZNetworkService postRequestWithBaseUrl:kDaySignUrl setParameters:dic success:^(id result) {
        
        YYLog(@"%@",result);
        
//        if ([result[@"errorCode"]integerValue]==0) {

//        }
    } fail:^(NSError *error) {
    } delegater:nil];
}

@end
